import { domainService } from '~/config/server'
import { NetService } from '~/utils/net.service'
import { Inject, Debounce } from "~/core/decorator";

export class TemplateService {

  @Inject()
  private netService: NetService

  /**
   * 模板按条件查询
   */
  public getTemplatesByCondition(data, page, sort?) {
    return this.netService.send({
      server: domainService.templateController.getTemplatesByCondition,
      data,
      page,
      sort
    })
  }
  /**
   * 根据模板类别获取模板列表
   * @param templateCatogory 模板类别
   */
  public getTemplateByCatogory(collectorStyle: string) {
    return this.netService.send({
      server: domainService.templateController.getTemplateByCatogory,
      data: {
        collectorStyle
      }
    })
  }
  /**
   * 新增模板信息
   */
  @Debounce()
  public createTemplate(data) {
    return this.netService.send({
      server: domainService.templateController.createTemplate,
      data: {
        id: data.id,
        collectorStyle: data.collectorStyle, // 模版形式
        templateCategory: data.templateCategory, // 模版类型
        templateName: data.templateName, // 模版名称
        templateStatus: data.templateStatus, //  模版状态
        companyCode: data.companyCode,
        templateCode: data.templateCode,
        templateContent: data.templateContent,
        overduePeriod: data.overduePeriod,
        isDefault: data.isDefault,
      }
    })
  }
  /**
   * 更新模板信息
   */
  @Debounce()
  public updateTemplate(data) {
    return this.netService.send({
      server: domainService.templateController.updateTemplate,
      data: {
        templateStyle: data.templateStyle, // 模版形式
        templateType: data.templateType, // 模版类型
        templateName: data.templateName, // 模版名称
        templateStatus: data.templateStatus, //  模版状态
        companyCode: data.companyCode,
        templateCode: data.templateCode,
        isDefault: data.isDefault,
        messageContent: data.messageContent,
        id: data.id
      }
    })
  }
  /**
   * 根据id删除模板
   */
  @Debounce()
  public deleteTemplateById(id: string) {
    return this.netService.send({
      server: domainService.templateController.deleteTemplateById,
      data: {
        id
      }
    })
  }
  /** 
   * 根据模板形式查询启用的模板
   */
  public getTemplatesByStyle(data) {
    return this.netService.send({
      server: domainService.templateController.getTemplatesByStyle,
      data: {
        style: data
      }
    })
  }

  /**
   * 根据逾期阶段查询模板
   */
  public getTemplateByOverduePeriod(data: any) {
    return this.netService.send({
      server: domainService.templateController.getTemplateByOverduePeriod,
      data
    })
  }
  /**
   * 导入话术模板
   */
  public importSpeechTemplate(data: any) {
    return this.netService.send({
      server: domainService.templateController.importSpeechTemplate,
      data
    })
  }
}

